using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RobotCreator : MonoBehaviour
{
    public int x = 10;
    public int y = 10;
    public int length = 5;
    public GameObject robot;
    public List<GameObject> robots;
    private void Start()
    {
        //Create();
    }
    public void Create(int count)
    {
        for (int i = 0; i < y; i++)
        {
            for (int j = 0; j < x; j++)
            {
                if (i * x + j >=count)
                {
                    return;
                }
                robots.Add(Instantiate(robot,new Vector3(length*i,this.transform.position.y,j*length),Quaternion.Euler(0,0,0)));
            }
        }
    }
    public void Unlock()
    {
        foreach (var robot in robots)
        {
            robot.GetComponent<WheelLegRobot>().rb.constraints = RigidbodyConstraints.None;
        }
    }
    public void ChangePid(RLTorch[] q_table)
    {
        for(int i = 0;i < q_table.Length; i++)
        {
            var new_pid = q_table[i].GetNewPid();
            robots[i].GetComponent<WheelLegRobotController>().x_angle_pid.kp = new_pid.x;
            robots[i].GetComponent<WheelLegRobotController>().x_angle_pid.ki = new_pid.y;
            robots[i].GetComponent<WheelLegRobotController>().x_angle_pid.kd = new_pid.z;
        }
    }
}
